package com.fick.tags;
/**
 * 显示指定channelid的栏目名称
 * @author 王浩强
 * 2009-08-14
 */
import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fick.hibernate.dao.ChannelDAO;
import com.fick.hibernate.model.Channel;

public class TitleTag extends TagSupport {
	private static Log log = LogFactory.getLog(TitleTag.class);
	
	//栏目id
	private int channelid;
	//是否带连接
	private boolean isLink=false;
	//<a>标签的属性
	private String linkAttr="";
	//显示内容
	private String show="";
	
	public int doStartTag() throws JspException {
		
		try {
			StringBuffer sb = new StringBuffer();
			ChannelDAO dao=new ChannelDAO();
			Channel channel=dao.findById(channelid);
			if (channel!=null) {
				if (isLink) {
					sb.append("<a href='");
					sb.append(channel.getUrl());
					sb.append("?channelid=");
					sb.append(channelid);
					sb.append("' ");
					sb.append(linkAttr);
					sb.append(" >");
					if (show.trim().length()>0) {
						sb.append(show);
					}else {
						sb.append(channel.getName());
					}
					sb.append("</a>");
				}else {
					if (show.trim().length()>0) {
						sb.append(show);
					}else {
						sb.append(channel.getName());
					}
				}
			}
			JspWriter out = pageContext.getOut();
			out.println(sb.toString());
			out.flush();
		}catch(IOException e)
		{
			log.error("标签显示错误"+e);
			e.printStackTrace();
		}
		return SKIP_BODY;
	}

	public int getChannelid() {
		return channelid;
	}

	public void setChannelid(int channelid) {
		this.channelid = channelid;
	}

	public boolean getIsLink() {
		return isLink;
	}

	public void setIsLink(boolean isLink) {
		this.isLink = isLink;
	}

	public String getLinkAttr() {
		return linkAttr;
	}

	public void setLinkAttr(String linkAttr) {
		this.linkAttr = linkAttr;
	}

	public String getShow() {
		return show;
	}

	public void setShow(String show) {
		this.show = show;
	}
}

